
import numpy as np
import cv2
import matplotlib.pyplot as plt


##参数
fileName=r'..\misc_pic\yl01_01.jpg'
#fileName=r'misc_pic\empire.jpg'
high_threshold =80
low_threshold=30

##载入图像
img = cv2.imread(fileName)
gray= cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)

gray = cv2.GaussianBlur(gray,(3,3),0)
edge_img = cv2.Canny(gray, 30, 80)

plt.gray()
plt.imshow(edge_img,interpolation="nearest")
plt.show()

minLineLength = 20
maxLineGap = 5
lines = cv2.HoughLinesP(edge_img,1,np.pi/180,50)

"""
for line  in lines:
    rho,theta=line[0]
    a = np.cos(theta)
    b = np.sin(theta)
    x0 = a*rho
    y0 = b*rho
    x1 = int(x0 + 1280*(-b))
    y1 = int(y0 + 1280*(a))
    x2 = int(x0 - 1280*(-b))
    y2 = int(y0 - 1280*(a))
    cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
"""

for line  in lines:
    x1,y1,x2,y2=line[0]
    cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)


#plt.gray()
plt.imshow(img,interpolation="nearest")
plt.imshow(img)
plt.show()


